#include <bits/stdc++.h>
#define ll long long
#define i128 __int128
using namespace std;

const int Maxn=4e5+6;
int n,Q;
int a[Maxn];

struct Frac{
    i128 x,y;
    Frac(){
        x=0,y=1;
    }
    Frac(i128 x,i128 y):x(x),y(y){}
};
Frac lans[Maxn];
vector<pair<int,Frac> >ot[Maxn];
vector<pair<int,int> >qs[Maxn];
i128 ggcd(i128 x,i128 y){
    return !y?x:ggcd(y,x%y);
}
inline i128 Lcm(i128 x,i128 y){
    return x/__gcd(x,y)*y;
}
inline bool operator <(const Frac x,const Frac y){
    i128 p=Lcm(x.y,y.y);
    i128 px=x.x*(p/x.y),py=y.x*(p/y.y);
    return px<py;
}

class BIT{
    #define lowbit(x) (x&-x)
    public: 
        inline void init(int nl){sz=nl;}
        inline void add(int x,Frac k){
            while(x) tr[x]=max(tr[x],k),x-=lowbit(x);
        }
        inline Frac query(int x){
            Frac ret;
            while(x<=sz) ret=max(ret,tr[x]),x+=lowbit(x);
            return ret;
        }
    private:
        Frac tr[Maxn];
        int sz;
}t;
void Write(i128 x){
    if(x>9) Write(x/10);
    putchar('0'+x%10);
}

int main(){
    freopen("value.in","r",stdin);
    freopen("value.out","w",stdout);
    scanf("%d",&n);
    t.init(n+4);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&Q);

    int nnn=2e7/n;

    for(int i=1;i<=n;i++){
        ll val=0;
        Frac ans(0,1);
        for(int j=i;j<=min(n,i+nnn);j++){
            val+=a[j];
            if(ans<Frac(val*val,j-i+1)){
                ans=Frac(val*val,j-i+1);
                ot[j].emplace_back(i,ans);
            }
        }
    }
    for(int i=1;i<=Q;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        qs[r].emplace_back(l,i);
    }
    for(int i=1;i<=n;i++){
        for(auto j:ot[i]){
            int l=j.first;Frac num=j.second;
            t.add(l,num);
        }
        for(auto j:qs[i]){
            int l=j.first,id=j.second;
            lans[id]=t.query(l);
        }
    }
    for(int i=1;i<=Q;i++){
        i128 x=lans[i].x,y=lans[i].y;
        i128 g=ggcd(x,y);
        if(g) x/=g,y/=g;
        Write(x),putchar(' '),Write(y);puts("");
    }

    // system("pause");
    return 0;
}
/*
5
-962 -445 -613 -9 920
3
1 5
3 5
1 3
*/